package com.taotao.protal.controller;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.taotao.common.util.JsonUtils;
import com.taotao.content.service.ContentService;
import com.taotao.pojo.TbContent;
import com.taotao.protal.web.pojo.AdNode;

@Controller
public class PageController {
	private static Logger LOGGER = LoggerFactory.getLogger(PageController.class);

	@Autowired
	private ContentService contentService;
	/**
	 * "srcB": "http://image.taotao.com/images/2015/03/03/2015030304360302109345.jpg",
        "height": 240,
        "alt": "",
        "width": 670,
        "src": "http://image.taotao.com/images/2015/03/03/2015030304360302109345.jpg",
        "widthB": 550,
        "href": "http://sale.jd.com/act/e0FMkuDhJz35CNt.html?cpdad=1DLSUE",
        "heightB": 240
	 */
	@RequestMapping("/index")
	public String showIndex(Model model) {
		List<TbContent> contents = contentService.getContentByCid(89L);
		List<AdNode> nodes = new ArrayList<>();
		for (TbContent content : contents) {
			AdNode node = new AdNode();
			node.setAlt(content.getTitle());
			node.setHeight(240);
			node.setHeightB(240);
			node.setHref(content.getUrl());
			node.setSrc(content.getPic());
			node.setSrcB(content.getPic2());
			node.setWidth(670);
			node.setWidthB(550);
			nodes.add(node);
		}
		model.addAttribute("ad1", JsonUtils.objectToJson(nodes));
		LOGGER.info("nodes="+nodes);
		return "index";
	}
}
